﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FJERP.BLL;
using FJERP.Model;

namespace FJERP.Handler
{
    /// <summary>
    /// Shipment 的摘要说明
    /// </summary>
    public class Shipment : IHttpHandler
    {
        ShipmentsBLL bll = new ShipmentsBLL();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"].ToString();
            System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(action);
            if (methodInfo != null)
            {
                methodInfo.Invoke(this, new object[] { context });
            }
        }
        public void smateShow(HttpContext context)
        {
            int id = Convert.ToInt32(context.Request["id"]);
            List<FJERP.Model.ShipmentMate> list = bll.ShowShipmentsMateByid(id);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void SearchY(HttpContext context)
        {
            StatisticsShipmentsBLL bll = new StatisticsShipmentsBLL();
            string TimeStart = context.Request["TimeStart"];
            string TimeEnd = context.Request["TimeEnd"];
            List<SearchYear> list = bll.SearchY(TimeStart, TimeEnd);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void SearchM(HttpContext context)
        {
            StatisticsShipmentsBLL bll = new StatisticsShipmentsBLL();
            string SYear = context.Request["SYear"];
            string TimeStart = context.Request["TimeStart"];
            string TimeEnd = context.Request["TimeEnd"];
            List<SearchMonth> list = bll.SearchM(SYear, TimeStart, TimeEnd);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void IntoMate(HttpContext context)
        {
            PurchaseBLL bll = new PurchaseBLL();
            int id = Convert.ToInt32(context.Request["id"]);
            List<PurchaseMate> list = bll.PurCheckMate(id);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void Pay(HttpContext context)
        {
            int id = Convert.ToInt32(context.Request["id"]);
            context.Response.Write(bll.ShipmentPay(id));
        }
        public void Add(HttpContext context)
        {
            Shipments s = new Shipments();
            s.Shipments_blitems = context.Request["Shipments_blitems"].ToString();
            s.Employee_Id = Convert.ToInt32(context.Request["Employee_Id"]);
            s.MemberCard_Id = Convert.ToInt32(context.Request["MemberCard_Id"]);
            s.WareHose_Id = Convert.ToInt32(context.Request["WareHose_Id"]);
            s.Shipments_Price = Convert.ToInt32(context.Request["Shipments_Price"]);
            string xml = context.Server.UrlDecode(context.Request.Form["xml"].ToString());  //xml解码
            context.Response.Write(bll.ShipMentsAddDo(s, xml));
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}